﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Blog.DAL.Interface;
namespace Blog.DAL
{
   public partial class tblMembers
   {
       #region Propertise
       private string _email;
       private string _fullname;
       private string _username;
       private string _password;
       private string _member_type;
       private bool _verified;
       private bool _banned;
       private string _member_ship;
       private int _mem_id;
       private string _gender;
       private string _country;
       private string _city;
       private string _about_me;
       private int _dayJoin;
       private int _monthJoin;
       private int _yearJoin;
       private string _address;
       private string _aCountry;
       private string _aCity;
       private int _livestart;
       private int _liveend;
       private string _major;
       private string _movie;
       private string _music;
       private string _book;
       private string _food;
       private string _game;
       private string _other;

       public string major { get { return _major; } set { _major = value; } }
       public string moive { get { return _movie; } set { _movie = value; } }
       public string music { get { return _music; } set { _music = value; } }
       public string book  { get { return _book; }  set  { _book = value; } }
       public string food  { get { return _food; }  set   { _food = value; } }
       public string game  { get  { return _game; } set   { _game = value; } }
       public string other { get { return _other; } set { _other = value; } }
       public int liveStart
       {
           get
           {
               return _livestart;
           }
           set
           {
               _livestart = value;
           }
       }
       public int liveEnd
       {
           get
           {
               return _liveend;
           }
           set
           {
               _liveend = value;
           }
       }

       public string address { get { return _address; } set { _address = value;} }
       public string aCountry { get { return _aCountry; } set { _aCountry = value; } }
       public string aCity { get { return _aCity; } set { _aCity = value; } }

       public int dayJoin { get { return _dayJoin; } set { _dayJoin = value; } }


       public int monthJoin { get { return _monthJoin; } set { _monthJoin = value; } }


       public int yearJoin { get { return _yearJoin; } set { _yearJoin = value; } }
       public string sex
       {
           get { return _gender; }
           set { _gender = value; }
       }
       public string country
       {
           get { return _country; }
           set { _country = value; }
       }

       public string city
       {
           get { return _city; }
           set { _city = value; }
       }
       public string about_me
       {
           get { return _about_me; }
           set { _about_me = value; }
       }

       public string email
       {
           get { return _email; }
           set { _email = value; }
       }

       public string fullname
       {
           get { return _fullname; }
           set { _fullname = value; }
       }

       public string username
       {
           get { return _username; }
           set { _username = value; }
       }
       public string password
       {
           get { return _password; }
           set { _password = value; }
       }
       public bool verified
       {
           get { return _verified; }
           set { _verified = value; }
       }
       public bool banned
       {
           get { return _banned; }
           set { _banned = value; }
       }
       public string member_ship
       {
           get { return _member_ship; }
           set { _member_ship = value; }
       }
       public string member_type
       {
           get { return _member_type; }
           set { _member_type = value; }
       }

       public int mem_id
       {
           get { return _mem_id; }
           set { _mem_id = value; }
       }
       private string _schoolName;
       private string _level;
       private int _yearStart;
       private int _yearEnd;
       private string _sCountry;
       private string _sCity;

       private string _jobName;
       private string _company;
       private string _task;
       private int _jobStart;
       private int _jobEnd;
       private string _jCountry;
       private string _jCity;

       public string sCountry
       {
           get
           {
               return _sCountry;
           }
           set
           {
               _sCountry = value;
           }
       }
       public string sCity
       {
           get
           {
               return _sCity;
           }
           set
           {
               _sCity = value;
           }
       }

       public string jCountry
       {
           get
           {
               return _jCountry;
           }
           set
           {
               _jCountry = value;
           }
       }
       public string jCity
       {
           get
           {
               return _jCity;
           }
           set
           {
               _jCity = value;
           }
       }

       public string schoolName
       {
           get
           {
               return _schoolName;
           }
           set
           {
               _schoolName = value;
           }
       }
       public string level
       {
           get
           {
               return _level;
           }
           set
           {
               _level = value;
           }
       }
       public int yearStart
       {
           get
           {
               return _yearStart;
           }
           set
           {
               _yearStart = value;
           }
       }
       public int yearEnd
       {
           get
           {
               return _yearEnd;
           }
           set
           {
               _yearEnd = value;
           }
       }

       public string jobName
       {
           get
           {
               return _jobName;
           }
           set
           {
               _jobName = value;
           }
       }
       public string company
       {
           get
           {
               return _company;
           }
           set
           {
               _company = value;
           }
       }
       public string task
       {
           get
           {
               return _task;
           }
           set
           {
               _task = value;
           }
       }
       public int jobStart
       {
           get
           {
               return _jobStart;
           }
           set
           {
               _jobStart = value;
           }
       }
       public int jobEnd
       {
           get
           {
               return _jobEnd;
           }
           set
           {
               _jobEnd = value;
           }
       }
#endregion
       public tblMembers()
       { 
            
       }
       
       public int add()
       {
           DB db = new DB();
           int check = db.sp_addmember(username, password, fullname, email);
           return check;
       }
       public void edit()
       {
       
       }
       public void delete()
       {
       
       }
       
       public int update() 
       {
           DB db = new DB();
           int check = Convert.ToInt32(db.sp_update_mem_info(fullname,sex,country,city,email,about_me,mem_id,dayJoin,monthJoin,yearJoin));
           return check;
       }
       public int update_school()
       {
           DB db = new DB();
           int check1 = Convert.ToInt32(db.sp_update_school(schoolName,sCity,yearStart,yearEnd,mem_id,sCountry));
           int check2 = Convert.ToInt32(db.sp_update_job(jCity,mem_id,jobName,company,jCountry,task,jobStart,jobEnd));
           return (check1 + check2);
       }

       public int update_address()
       {
           DB db = new DB();
           var a = from c in db.tblmem_addresses where c.mem_id.Equals(mem_id) select c.mem_id;
           if (a.Count() == 0)
           {
               return db.sp_insert_address(address, aCountry, aCity, liveStart, liveEnd, mem_id);
           }
           else
               return db.sp_update_address(address, aCountry, aCity, liveStart, liveEnd, mem_id);
       }

       public int update_interested()
       {
           DB db = new DB();
           var a = from c in db.tblmem_interests where c.mem_id.Equals(mem_id) select c.mem_id;
           if (a.Count() == 0)
           {
               return db.sp_insert_interest(mem_id,major,game,music,book,food,other);
           }
           else
               return db.sp_update_interest(mem_id,major,game,music,book,food,other);
       }

       public void Save()
       {
           DB db = new DB();
           db.SubmitChanges();
       }
       

    }
}
